package com.genesis.yunnanji.adapter;

import android.content.Context;
import android.content.Intent;
import android.media.Image;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.genesis.yunnanji.R;
import com.genesis.yunnanji.activity.WebActivity;
import com.genesis.yunnanji.bean.SupBean;
import com.genesis.yunnanji.config.GenesisApiConfig;
import com.lidroid.xutils.BitmapUtils;

import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2017/11/13.
 */

public class SupSpecialAdapter extends BaseQuickAdapter<SupBean.ResultBean.ProductBean, BaseViewHolder> {
    private Context context;

    public SupSpecialAdapter(Context context, @Nullable List<SupBean.ResultBean.ProductBean> data) {
        super(R.layout.layout_supspecail_item, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final SupBean.ResultBean.ProductBean item) {
        BitmapUtils bitmapUtils = new BitmapUtils(context);
        ImageView img = (ImageView) helper.getView(R.id.iv_supspecial_iv);
        ViewGroup.LayoutParams layoutParams = img.getLayoutParams();
        bitmapUtils.display(img, GenesisApiConfig.PIC_HOST + item.getCover_img()
                + String.format("?x-oss-process=image/resize,m_fill,w_%d,h_%d", layoutParams.width, layoutParams.height));
        LinearLayout view = helper.getView(R.id.rl_supspecial_rl);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, WebActivity.class);
                intent.putExtra("url", item.getTarget_link());
                context.startActivity(intent);
            }
        });
        helper.setText(R.id.tv_supspecial_tv, item.getProduct_title());

    }
}
